// 创建计数器切片slice
// 导入创建切片的函数
import { createSlice } from "@reduxjs/toolkit";
import { clear } from "console";
// 定义初始化状态
export type userInfoType = {
  userName?: string;
  password?: string;
  phone?: string;
  email?: string;
  nickname?: string;
  gender?: string;
  id?: string;
  intro?: string;
};
const userInfo: userInfoType = {
  userName: "",
  password: "",
  nickname: "",
} as userInfoType;
// 创建切片
const counterSlice = createSlice({
  // 切片名称
  name: "user",
  // 初始化状态
  initialState: userInfo,
  // 定义处理器
  reducers: {
    // 设置用户信息
    setUserInfo: (state, action) => {
      // const { nickname, userName } = action.payload;
      console.log("调用redux", action.payload);
      return action.payload;
    },
    clearUserInfo: () => {
      return userInfo;
    },
  },
});

// 导出动作
export const { setUserInfo, clearUserInfo } = counterSlice.actions;
// 导出处理器
export default counterSlice.reducer;
// 导出异步操作动作
// export const syncAddvalue = (value) => (dispatch) => {
//   setTimeout(() => {
//     dispatch(addValue(value));
//   }, 2000);
// };
